<template>
	<view class="index-box">
		<view class="content"><leaveList :leaveList="leaveList"></leaveList></view>
	</view>
</template>

<script>
import leaveList from '@/pages/components/leaveList.vue';
export default {
	data() {
		return {
			leaveList: [],
			hasMore:true,
			dataEnd:false,
			
			current: 1,
			size: 10
		};
	},
	onReachBottom() {
		this.handleToLower()
		console.log('滑动到100px')
	},
	methods: {
		handleToLower(){
			if(this.hasMore){
				this.current+=this.current
				this.reloadRequest()
			}else{
				this.dataEnd=true
			}
		},
		//  `status` int DEFAULT NULL COMMENT '1.辅导员未审批  2.辅导员已审批（同意）3.辅导员已审批（不同意）4.书记未审批 5.书记已审批（同意）6.书记已审批（不同意）',
		formatLeaveStatus(value) {
			value=value.trim()
			switch (value) {
				
				case '1':
					return '辅导员未审批';
				case '2':
					return '等待书记批准';
				case '3':
					return '辅导员不批准';
				case '4':
					return '请假申请';
				case '5':
					return '书记已批准';
				case '6':
					return '书记不批准';
				default:
					return '未知状态';
			}
		},
		reloadRequest() {
			let _this = this;
			//请求首页数据
			uni.request({
				url: this.baseUrl + "/secretary/home/searchSecretaryHome?satoken="+uni.getStorageSync('satoken'),
				method: 'GET',
				data: {
					current: _this.current,
					size: _this.size,
				},
				withCredentials: true,
				headers: {
					//"content-type": "application/x-www-form-urlencoded",
					// token: localStorage.getItem('token')
				},
				success: res => {
					_this.leaveList = res.data.data.records;
					if(_this.leaveList){
						//转码
						_this.leaveList = _this.leaveList.filter(iterm => {
							iterm.status = _this.formatLeaveStatus(iterm.status);
							return iterm.status;
						});
						//数据拼接
						//_this.leaveList=[..._this.leaveList,...res.data.data.records]
					}else{
						_this.hasMore=false
						_this.dataEnd=true
					}
				},
				complete() {
					uni.hideLoading()
				}
			});
		}
	},
	onShow() {
		this.leaveList=[]
		uni.showLoading({
			title:"加载中"
		})
		this.reloadRequest();
	},
	
	components: {
		leaveList
	}
};
</script>

<style lang="scss">
.index-box {
	width: 95%;
	margin: 0 auto;
}
</style>
